<?php
namespace app\admin\command;

use think\Config;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
class ReceiveGoods extends Command{
    protected function configure()
    {
        $this->setName('ReceiveGoods')->setDescription('订单监测');
    }
    /**
     * 线性释放
     */
    protected function execute(Input $input, Output $output)
    {
        echo date('Y-m-d H:i:s') . "订单监测(每分钟一次)\n";
        $this->auction();
        $this->updateOrder();
    }
    public function auction()
    {
        $where=[];
        $where['order_status']=5;
       $list=Db::name('order')->where($where)->select();
       foreach ($list as $k=>$v){
           $time=bcsub(time(),$v['createtime']);
         if($time>=604800){
            $data=[];
            $data['order_status']=6;
             $data['updatetime']=time();
             Db::name('order')->where('order_id',$v['order_id'])->update($data);
         }
       }
       echo'SUCCESS';
    }
    public function updateOrder()
    {
        $where=[];
        $where['order_status']=1;
        $list=Db::name('order')->where($where)->select();
        foreach ($list as $k=>$v){
            $time=bcsub(time(),$v['createtime']);
            if($time>=1800){
                $data=[];
                $data['order_status']=3;
                $data['updatetime']=time();
                Db::name('order')->where('order_id',$v['order_id'])->update($data);
                Db::name('goods')->where('goods_id',$v['goods_id'])->setInc('stock',1);
            }
        }
        echo'SUCCESS';
    }

}
